package com.taotao.manager.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.taotao.manager.service.ItemParamItemService;
import com.taotao.pojo.TbItemParamItem;

/**
 * 规格参数商品信息
 * <p>Title: ItemParamItemController</p>
 * <p>Description: </p>
 * @author	laibingrong
 * @date	2017年11月20日下午1:56:39
 * @version 1.0
 */
@RequestMapping("/item/param/item")
@Controller
public class ItemParamItemController {
	
	private static final Logger LOGGER = LoggerFactory.getLogger(ItemParamItemController.class);
	
	@Autowired
	private ItemParamItemService itemParamItemService;

	/***
	 * 根据商品类目ID查询是否存在规格参数
	 * <p>Title: queryItemParamById</p>
	 * <p>Description: </p>
	 * @param itemCatId
	 * @return
	 */
	@RequestMapping(value="/{itemId}",method=RequestMethod.GET)
	public ResponseEntity<TbItemParamItem> queryItemParamById(@PathVariable("itemId") long itemId){
		try{
			TbItemParamItem itemParamItem = new TbItemParamItem();
			itemParamItem.setItemId(itemId);
			TbItemParamItem result = itemParamItemService.queryOne(itemParamItem);
			 
			if(result == null) {
				return ResponseEntity.status(HttpStatus.NOT_FOUND).body(null);
			}
			return ResponseEntity.ok(result);
		}catch (Exception e) {
			LOGGER.error("查询商品类目对应的规格参数模板失败,itemCatId = "+itemId,e);
		}
		return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
	} 
}
